package com.sgb.kjwl.view.ui.activity.self.carMaster;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMyCarriageManageBinding;
import com.sgb.kjwl.view.ui.fragment.transport.MyCarriageManageFragment;
import com.sgb.link.router.PathLogistics;
import com.sgb.link.view.widget.CustomXTabLayout;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;

//承运管理
public class CarriageManageActivity extends BaseActivity<BaseViewModel, ActivityMyCarriageManageBinding> {

    public static void start(Context context) {
        Intent intent = new Intent(context, CarriageManageActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_my_carriage_manage;
    }

    @Override
    protected void createViewModel() {

    }

    @Override
    protected void init() {
        mBinding.include.rightView.setText("发布找货");
        mBinding.include.titleView.setText("承运需求");
        mBinding.include.rightView.setVisibility(View.VISIBLE);
        mBinding.include.rightView.setOnClickListener(this);
        mBinding.include.ivBack.setOnClickListener(this);
        initFragment();
    }

    private void initFragment() {
        String[] mTabs = new String[]{"全部", "正常", "已失效"};
        //viewPager适配器
        ArrayList<Fragment> fragments = new ArrayList<>();
        //添加页面
        for (int i = 0; i < mTabs.length; i++) {
            fragments.add(MyCarriageManageFragment.newInstance(i));
        }
        SlidingFragmentPagerAdapter adapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), fragments, mTabs);
        mBinding.vpMyCarriage.setAdapter(adapter);
        mBinding.vpMyCarriage.setOffscreenPageLimit(2);
        mBinding.tabLayout.setNormalColor96();
        mBinding.tabLayout.setupWithViewPager(mBinding.vpMyCarriage);
        mBinding.tabLayout.addOnTabSelectedListener(new CustomXTabLayout.SimpleSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mBinding.vpMyCarriage.setCurrentItem(tab.getPosition());
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.right_view://发布找货
                ARouter.getInstance().build(PathLogistics.CarriagePushActivity).navigation();
                break;
        }
    }
}
